package org.dna.mybatis.criteria;

/**Logic expression criterion, AND or OR
 */
public final class LogicExpression implements Criterion {

    public enum Operator {

        AND, OR
    };
    private Criterion m_lhp;
    private Criterion m_rhp;
    private Operator m_op;

    LogicExpression(Criterion lhp, Operator operator, Criterion rhp) {
        m_lhp = lhp;
        m_rhp = rhp;
        m_op = operator;
    }

    public String getSql() {
        StringBuilder sb = new StringBuilder();
        sb.append("(").append(m_lhp.getSql()).append(" ").append(m_op.toString()).append(" ").append(m_rhp.getSql()).append(")");
        return sb.toString();
    }

    public boolean verify(Criteria criteria) {
        return m_lhp.verify(criteria) && m_lhp.verify(criteria);
    }
    
    public void bind(Criteria crit) throws CriteriaException {
        m_lhp.bind(crit);
        m_rhp.bind(crit);
    }
}
